// Copyright (c) Appeon. All rights reserved.
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. 
// You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0.

using System.Collections.Generic;
using System.Linq;

namespace SnapObjects.Data
{
    internal class ConditionElement : SqlElement
    {
        public ConditionElement(
            string left, SqlOperator sqlOperator, object right,
            SqlRightType rightType, bool isUnaided = false)
            : this(left, sqlOperator, right, rightType, "", isUnaided)
        {

        }

        public ConditionElement(
            string left, SqlOperator sqlOperator, object right,
            SqlRightType rightType, string name, bool isUnaided = false) : base(name)
        {
            this.Left = left;
            this.Operator = sqlOperator;
            this.Right = right;
            this.RightType = rightType;
            this.IsUnaided = isUnaided;

            this.AndOr = new Dictionary<SqlElement, SqlStitchingType>();
        }

        public override SqlElementType ElementType => SqlElementType.Condition;
        public bool IsUnaided { get; }
        public string Left { get; }
        public SqlOperator Operator { get; }
        public object Right { get; }
        public SqlRightType RightType { get; }
        public IDictionary<SqlElement, SqlStitchingType> AndOr { get; private set; }

        public override SqlElement Clone()
        {
            return new ConditionElement(
                this.Left, this.Operator, this.Right, this.RightType, this.ElementName, this.IsUnaided)
            {
                AndOr =
                    this.AndOr.ToDictionary(m => m.Key.Clone(), m => m.Value)
            };
        }
    }
}
